<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
/*echo $_REQUEST['pro_id'];
echo $_REQUEST['project_name'];
echo $_REQUEST['project_manager'];
echo $_REQUEST['pro_description'];
echo $_REQUEST['start_date'];
echo $_REQUEST['complete_date'];
echo $_REQUEST['pro_status'];*/
include "../../operations/connection.php";
	
try {
	
	$checkExsit = mysql_query("select * from pr_project where IDView='".$_REQUEST['pro_idview']."' or NameProject='".$_REQUEST['project_name']."'");
	if (mysql_num_rows($checkExsit)==0) {
		$query = "insert into pr_project(IDProject,IDView,NameProject,Description,IDManager,DateStart,DateComplete,Status)
		values('".$_REQUEST['pro_id']."','".$_REQUEST['pro_idview']."','".$_REQUEST['project_name']."','".$_REQUEST['pro_description']."',
		'".$_REQUEST['project_manager']."','".$_REQUEST['start_date']."','".$_REQUEST['complete_date']."','".$_REQUEST['pro_status']."')";
		
		mysql_query($query);
		header( 'Location: ../../project_admin.php?content=admin/project/addcomposition.php&id='.$_REQUEST['pro_id']);
	}else{
		while ($row = mysql_fetch_array($checkExsit)) {	
			$flagexist = 2;
			if ($row['IDView']==$_REQUEST['pro_idview']) {
				$flagexist=1;
			}
			$_SESSION['projectexist'] = array($flagexist,$_REQUEST['pro_idview'],$_REQUEST['project_name'],$_REQUEST['project_manager'],$_REQUEST['start_date'],$_REQUEST['complete_date'],$_REQUEST['pro_status'],$_REQUEST['pro_description']);
			if ($row[IDView]==$_REQUEST['valview']) {
				header( 'Location: ../../project_admin.php?content=admin/project/newproject.php');	
			}else{
				header( 'Location: ../../project_admin.php?content=admin/project/newproject.php');	
			}
			break;
		}
	}
	
} catch (Exception $e) {
	mysql_close($connection);
	header( 'Location: ../../project_admin.php?content=admin/project/list_project.php' );
}

mysql_close($connection);

?>